import com.tc.mongo.service.MongodbService;
import lombok.extern.java.Log;
import org.bouncycastle.util.encoders.Base64;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext.xml","file:src/main/webapp/WEB-INF/mvc-servlet.xml" }, inheritLocations = true)
@ActiveProfiles(value = "test")
@Log
public class test7 {

    @Autowired
    private MongodbService mongodbService;
    @Test
    public void demo() throws Exception{
        InputStream imageInputStream = mongodbService.getImageInputStream("1f01dd660032480d9939971672158a69.jpg", true);
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        byte[] buffer = new byte[4096];
        int n = 0;
        while (-1 != (n = imageInputStream.read(buffer))) {
            output.write(buffer, 0, n);
        }
        System.out.println(imageInputStream!=null);
        System.out.println(output.toByteArray().length);
    }
    @Test
    public void demo1() throws Exception{
        String filePostfix = ".jpg";
        String fileType = filePostfix != null ? filePostfix.substring(1) : "";
        String fileName = "1f01dd660032480d9939971672158a69";
        byte[] decode = Base64.decode("/9j/4AAQSkZJRgABAQIAJQAlAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcU FhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgo KCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCADIAMgDASIA AhEBAxEB/8QAHAAAAQQDAQAAAAAAAAAAAAAABAADBQYCBwgB/8QAOxAAAgEDAgQEBQEGBQQDAAAA AQIDAAQRBSEGEjFBEyJRYQcycYGRFCNCobHB0QgVFmLhJDNSciWC8P/EABoBAAIDAQEAAAAAAAAA AAAAAAIDA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ro2uVBZSeUHuB W2qmcWq9hT0ujZ/DtzFNGeRgeX8ilVTsLt7EyTBipVeo70q50+DeTuPQa8mV7LghzRMZ6UqVYWOC I23oSDRGvkujDMnJK5wD6n/mlSo4yVjTci7hZGlRBWOk3elaiZZljbwz1B3UirfxPYxa3w3Ohx54 jhvQGlSp3lW8nG37FeMuDco5R1kva3strI2TGSmfoa25/h71Pw9D1WxB/aeMHH0I3pUqDinkaZ0f I6wbRK/EOMQRtdRZJAHNmqxpKNypPKCM7D1+tKlXVw5H8RyaSWtfZfXMQULAMBFAZgfmbufzmmWm 5R1pUq8Jlt1bpnr8cKZSQBd6sI0ZR1qFibxJy7Nk9TSpVE+g30FTal+zEMW59fSgL2UQ2NxITvyE D3NKlW7xEnllGPyKfFlZs5MpO/UhOUfU7VsTgnVo3hFvdEeOqgKR++MfzpUq9NmlXi2zit8a6JXX 7qC5tTa9MnYnqp7VSbq3khlEbbluh9aVKtHhfguKMeVuntl64JliSEW8rBrgDyt7egqQ4qggksWL kC4APh+5/tSpVhyLj5O0Nmt4ezUGtyMbIxlc82R7g9qtXA8qT6RBg5ZPKf8AmlSrZ/ILpMPB+gRx TZqBEkGFeU8xHYilSpU3xclTiSRizPVs/9k=");
        boolean attachment = mongodbService.createAttachment(decode, fileName, fileType);
        System.out.println(attachment);
    }

}
